<?php
class ColegiadosController extends AppController{
public $components =array('Paginator');
public $uses=array('User');
public $layout='sib';

function index (){
    $colegiados= $this->User->find ('all', array('recursive'=>-1));
    $this->set(compact('colegiados'));
}


public function inscribir(){
        if ($this->request->is('post')) {
            //debug($this->request->data);die;
            $this->User->create(); 
            
            if ($this->User->save($this->request->data)) { 
                $this->Session->setFlash('Los datos han sido guardados con exito','mensajeBueno'); 
                $this->redirect(array('action' => 'index'), null, true); 
            } else { 
                $this->Session->setFlash('Los datos no se pudieron guardar','mensajeError'); 
            }
        }
    }
    
function editar($id = null) {

        $this->User->id = $id;
        if (!$this->User->exists()) {
            throw new NotFoundException(__('Invalido'));
        }
        if ($this->request->is('post')) {
            //debug($this->request->data);exit;
            $this->User->id = $id;
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('seguardo correctamente'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('Error. Intentelo de nuevo'));
            }
        }else{
            $this->request->data = $this->User->read(null, $id);
        }
    }
    
function eliminar($id) {
        if ($this->request->data('post')) {
            throw new MethodNotAllowedException();
        }
        if ($this->User->delete($id)) {
            $this->Session->setFlash('el colegiado' . $id . 'Ha sido eliminado');
            $this->redirect(array('action' => 'index'));
        }
    }    
}
?>
